export default class HomeUI extends Laya.Script {

    constructor() { 
        super(); 
    /** @prop {name:txt_Score, tips:"字符串类型示例", type:Node, default:null}*/
    this.txt_Score=null;
    /** @prop {name:txt_timer, tips:"字符串类型示例", type:Node, default:null}*/
    this.txt_timer=null;
    this.time=10;
        this.score=0;
        // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    }
    onAwake(){
        Laya.stage.on("GameOver",this,function(){
           Laya.timer.pause(); 
        })
        Laya.stage.on("StartPlay",this,function(){
                this.time=10;
                this.score=0;
                this.txt_Score.text="分数:"+this.score;
        })
        Laya.stage.on("AddScre",this,this.AddScore)
        Laya.timer.loop(1000,this,function(){
            this.time-=1;
            this.txt_timer.text="倒计时:"+this.time;
            if(this.time<=0){                
                Laya.timer.pause();
                Laya.stage.event("GameOver");


            }
        })
    }
    AddScore(score=1){
        this.score+=score;
        this.txt_Score.text="分数:"+this.score;
        }

}